home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Utilities / Interfaces / ODMemory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  4.1 KB  |  149 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ODMemory.h
  3.  
  4.     Contains:    Memory calls (wrappers around MemMgr.h) that throw exceptions.
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11.     In Progress:
  12.         
  13. */
  14.  
  15. #ifndef _ODMEMORY_
  16. #define _ODMEMORY_
  17.  
  18. #ifndef _ODTYPES_
  19. #include "ODTypes.h"
  20. #endif
  21.  
  22. #ifndef __CODEFRAGMENTS__
  23. #include <CodeFragments.h>
  24. #endif
  25.  
  26.  
  27. #ifdef _OD_IMPL_SHARE_UTILS_
  28. #pragma import on
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. #define DEFAULT(V)    =(V)
  33. extern "C" {
  34. #else
  35. #define DEFAULT(V)    /**/
  36. #endif
  37.  
  38. //========================================================================================
  39. // Type definitions
  40. //========================================================================================
  41.  
  42. typedef struct MemHeap MemHeap;
  43. typedef MemHeap* ODMemoryHeapID;        // An anonymous pointer type
  44.  
  45. typedef ODULong ODBlockSize;
  46.  
  47. //========================================================================================
  48. // Constant definitions
  49. //========================================================================================
  50.  
  51. #define kDefaultHeapID ((ODMemoryHeapID) 0L)
  52.  
  53.  
  54. //========================================================================================
  55. // Initialization        (MUST call this before using ODNewPtr[Clear] or ODGetDefaultHeap)
  56. //========================================================================================
  57.  
  58. OSErr InitODMemory( );
  59.  
  60. //========================================================================================
  61. // Operations on heaps
  62. //========================================================================================
  63.  
  64. ODMemoryHeapID    ODGetDefaultHeap();
  65. //ODMemoryHeapID    ODGetSystemHeap();
  66.  
  67. ODMemoryHeapID    ODCreateHeap(ODULong initialSize, ODULong growBy, Boolean fromSysMemory,
  68.                             const char *name);
  69. void            ODDestroyHeap(ODMemoryHeapID heapID);
  70.  
  71. //========================================================================================
  72. // Operations on pointer based blocks
  73. //========================================================================================
  74.  
  75. // ----- Allocation and freeing
  76.  
  77. void*        ODNewPtr(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  78. void*        ODNewPtrClear(ODBlockSize size, ODMemoryHeapID heapID  DEFAULT(kDefaultHeapID) );
  79. void*        ODReallocate(void *block, ODBlockSize newSize);
  80. void         ODDisposePtr(void *block);
  81.  
  82. // ----- Utilities
  83.  
  84. ODMemoryHeapID ODRecoverHeapID(const void *block);
  85.  
  86. //========================================================================================
  87. // Operations on handle based blocks
  88. //========================================================================================
  89.  
  90. // ----- Allocation and freeing
  91.  
  92. ODHandle    ODNewHandle(ODBlockSize howBig);
  93. void        ODDisposeHandle(ODHandle handle);
  94. ODHandle    ODCopyHandle(ODHandle handle);
  95.  
  96. // ----- Block size accessors
  97.  
  98. ODULong        ODGetHandleSize(ODHandle handle);
  99. void        ODSetHandleSize(ODHandle handle, ODBlockSize size);
  100.  
  101. // ----- Locking and unlocking
  102.  
  103. void*        ODLockHandle(ODHandle handle);
  104. void        ODUnlockPtr(void* ptr);
  105. void        ODUnlockHandle(ODHandle handle);
  106.  
  107. //========================================================================================
  108. // Utility functions
  109. //========================================================================================
  110.  
  111. ODBoolean    ODHaveFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  112.                              ODBoolean appHeap DEFAULT(kODFalse) );
  113. void        ODRequireFreeSpace( ODSize haveTotal, ODSize haveContig DEFAULT(0),
  114.                                 ODBoolean appHeap DEFAULT(kODFalse) );
  115. void        ODCheckAppHeapSpace();
  116.  
  117.  
  118. void        ODBlockMove(const void *from, void *to, ODBlockSize size);
  119.  
  120. void        ODBlockIsObject( void *block, ODBoolean isObject );    // Called by ODObject::somInit
  121. ODBoolean    ODIsBlockAnObject( const void *block );
  122.  
  123. #ifdef _PLATFORM_MACINTOSH_
  124. #ifndef __QUICKDRAW__
  125. #include <QuickDraw.h>
  126. #endif
  127.  
  128. RgnHandle    ODNewRgn( );                                    // Allocates rgn in temp-mem.
  129.  
  130. #ifdef __cplusplus
  131.     inline RgnHandle ODCopyRgn( RgnHandle r )
  132.             {return (RgnHandle)ODCopyHandle((ODHandle)r);}
  133. #else
  134.     #define ODCopyRgn(R)    ((RgnHandle)ODCopyHandle((ODHandle)(R)))
  135. #endif
  136.  
  137. #endif /*_PLATFORM_MACINTOSH_*/
  138.  
  139.  
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143.  
  144. #ifdef _OD_IMPL_SHARE_UTILS_
  145. #pragma import off
  146. #endif
  147.  
  148. #endif /*_ODMEMORY_*/
  149.